import { createStoreBindings } from 'mobx-miniprogram-bindings'
import { store } from '@/utils/store'
import { call } from '@/utils/request'
import { showMsg, showLoading, hideLoading, showSuccess } from '@/utils/toast'

Page({
  data: {
    dateList: [],
    dateSelectedIndex: 0,
    activityList: [],
    isRefreshPull: false,
  },
  onLoad(options) {
    this.storeBindings = createStoreBindings(this, {
      store,
      fields: ['window_info'],
    })
  },
  onUnload() {
    // 解绑
    this.storeBindings.destroyStoreBindings()
  },
  onShow() {
    this.init()
  },
  init() {
    showLoading()
    call('/getActivityListAll').then(res => {
      res.forEach(item => {
        item.month_day = item.date.slice(5)
      })
      this.setData({
        dateList: res,
        activityList: res[this.data.dateSelectedIndex].activitieList,
        isRefreshPull: false,
      })
      hideLoading()
    })
  },
  selectDate({ mark: { index } }) {
    if (this.data.dateSelectedIndex === index) return
    this.setData({
      dateSelectedIndex: index,
      activityList: this.data.dateList[index].activitieList,
    })
  },
  toInfoPage({ mark: { id } }) {
    wx.navigateTo({
      url: '/pages/activity_info/index?id=' + id,
    })
  },
})
